import { createVNode, render } from 'vue';
import Loading from './index.vue'


// createVNode 把模板.vue文件转换成 VNode
// 使用 render 函数将vNode 挂在的 DOM上

var body = document.body
let loadEl;
let instance;
Loading.show = function(options) {
    if(loadEl) return;
    loadEl = document.createElement('div')
    loadEl.className = 'loading_container'
    body.appendChild(loadEl)
    // 创建实例并render
    instance = createVNode(Loading, options)
    render(instance, loadEl);

    console.log(Loading);
}

Loading.text = function(title) {
    instance.component.exposed.changeTitle(title)
}



Loading.hide = function() {
    if(!loadEl) return
    body.removeChild(loadEl)
    instance = null
    loadEl = null;
}

Loading.install = function (app) {
    app.config.globalProperties.$Loading = Loading
}

export default Loading
